import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/styles/index.scss' // global css
import App from './App'
import router from './router'
import store from './store'
import moment from 'moment'
import i18n from './lang' // Internationalization
import './icons' // icon
import './errorLog' // error log
import * as filters from './filters' // global filters
import './mock' // simulation data
// font-awesome
import 'font-awesome/css/font-awesome.css'
/*
 * 注册 - 业务模块
 */

import dashboard from '@/module-dashboard/' // 面板
import xczx from '@/module-xczx/' // 学成在线

Vue.prototype.forumTreeData = function (froum) {
  for (let i in froum) {
    froum[i].value = froum[i].courseCategoryId
    froum[i].label = froum[i].name
  }
  let temp = {}
  let ans = []
  for (let i in froum) {
    temp[froum[i].value] = froum[i]
  }
  for (let i in temp) {
    if (temp[i].parentid != 0) {
      if (!temp[temp[i].parentid].categoryTreeNodes) {
        temp[temp[i].parentid].categoryTreeNodes = []
      }
      temp[temp[i].parentid].categoryTreeNodes.push(temp[i])
    } else {
      ans.push(temp[i])
    }
  }
  return ans
}

Vue.use(dashboard, store)
Vue.use(xczx, store)

/*
 * 注册 - 组件
 */

// 饿了么
Vue.use(Element, {
  size: 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})
// 过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
// 时间转换
Vue.filter('dateformat', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})
Vue.config.productionTip = false
/* eslint-disable */
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  template: '<App/>',
  components: { App }
})
